Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: handle bad url-encoded Cookie session token #1269

Closed
wants to merge 7 commits into from

Conversation

@matthew-white
Copy link
Member

matthew-white commented Nov 9, 2024

I'm noticing in the test that cookies.session is already decoded: headers.Cookie is 'session=aloho%25eamora', while cookies.session is 'aloho%eamora'. Can we just removing the decoding here altogether? It kind of seems like we're double-decoding. Unlike with CSRF tokens in the request body (#1260), I don't think we intended to double-decode here.

Looking at the commit history for this file, it looks like previously, the code retrieved the token from context.headers.cookie, then decoded it. Later on (in #910), the code retrieved the token from context.cookies, but it continued to decode it. If context.cookies automatically decodes, then I think when context.headers.cookie was replaced with context.cookies, the decodeURIComponent() probably should have been removed as well.

lib/http/preprocessors.js Outdated Show resolved Hide resolved
@@ -272,6 +272,30 @@ describe('preprocessors', () => {
context.auth.session.should.eql(Option.of(new Session({ test: 'session' })));
}));

it('should reject cookie which cannot be url-decoded', () => {
let caught = false;
Promise.resolve(authHandler(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this promise needs to be returned in order for Mocha to wait on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very possible. Do tests on line 188 and 208 need the same change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, that sounds right to me. If there's an assertion in a promise chain, that assertion will only affect the success/failure of the test if the promise is returned to Mocha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing tests fixed at #1286

@alxndrsn
Copy link
Contributor Author

Can we just removing the decoding here altogether?

That would be great 👍 In which case, this PR would be superseded by #1290

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Dec 3, 2024

#1290 has been merged.

@alxndrsn alxndrsn closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants